﻿using System;
using System.Linq;
using SoTools.Communicator.TestMessage;

namespace SoTools.Communicator.TestConsole
{
	class Program
	{
		static void Main(string[] args)
		{
			try
			{
				var communicator = new Communicator();

				communicator.GenerateObservable<Message>().Subscribe(m => Console.WriteLine("Message1 received"));

				communicator.Listen();

				Console.WriteLine("Listening...");

				while (true)
				{
					var s = Console.ReadLine();
					if (!String.IsNullOrWhiteSpace(s) && s.ToLowerInvariant() == "q")
						break;
					if (s == "1")
						communicator.Publish(new Message { Content = "I'm a 1" });
					if (s == "2")
						communicator.Publish(new Message { Content = "I'm a 2" });
					if (s == "j")
						communicator.Publish(new Message { Content = String.Join(" ", Enumerable.Repeat("I'm a jumbo!", 100)) });
				}
			}
			catch (Exception exception)
			{
				Console.WriteLine(exception.ToString());
				Console.ReadLine();
			}
		}
	}

}
